package com.jsmtr.rms.service.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.jsmtr.rms.entity.*;
import org.springframework.stereotype.Service;

import com.jsmtr.rms.dao.DaoService;
import com.jsmtr.rms.service.IDoSZService;
import com.jsmtr.rms.utils.BeanTools;
import com.jsmtr.rms.utils.StringTools;
import com.jsmtr.rms.utils.db.DbUtil;

@Service
public class DoSZService implements IDoSZService {

    @Resource
    private DaoService dao;

    public void setDao(DaoService dao) {
        this.dao = dao;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> getResumes(int page, int perpage, DUserResume resume, Map<String, Object> param) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer queryHQL = new StringBuffer("from DUserResume r where 1=1 ");
        StringBuffer countHQL = new StringBuffer("select count(*) from DUserResume r where 1=1 ");
        StringBuffer condition = new StringBuffer();

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");
        Object rcount = param.get("rcount");

        Map<String, Object> _map = new HashMap<String, Object>();

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("agefrom", sdf.parse(_date));
            condition.append(" and r.birthday<=:agefrom");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("ageto", sdf.parse(_date));
            condition.append(" and r.birthday>=:ageto");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            _map.put("workyearfrom", Integer.parseInt(workyearfrom.toString()));
            condition.append(" and r.workexperience>=:workyearfrom");
        }
        if (StringTools.notEmpty(workyearto)) {
            _map.put("workyearto", Integer.parseInt(workyearto.toString()));
            condition.append(" and r.workexperience<=:workyearto");
        }
        if (StringTools.notEmpty(heightfrom)) {
            _map.put("heightfrom", Integer.parseInt(heightfrom.toString()));
            condition.append(" and r.height>=:heightfrom");
        }
        if (StringTools.notEmpty(heightto)) {
            _map.put("heightto", Integer.parseInt(heightto.toString()));
            condition.append(" and r.height<=:heightto");
        }

        resume.setRcount(null);
        if (StringTools.notEmpty(rcount)&&Integer.parseInt(rcount.toString())>0){
            _map.put("rcount", Integer.parseInt(rcount.toString()));
            condition.append(" and  nvl(r.rcount,0) >= :rcount");
        }

        condition.append(BeanTools.hqlWhere(resume, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);

        double count = ((Long) dao.findUnique(countHQL.toString(), _map)).doubleValue();
        double pageCount = Math.ceil(count / (double) perpage);

        List<DUserResume> list = dao.findLimit(queryHQL.toString(), _map, perpage * (page - 1), perpage);

        map.put("pageCount", pageCount);
        map.put("count", count);
        map.put("list", list);
        return map;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DUserResume> getResumes(String[] ids) throws Exception {
        return dao.find("from DUserResume where id in(:idlist)", ids);
    }

    @Override
    public ProjectInfoFlow getCurrentFlow(String fid) throws Exception {
        return (ProjectInfoFlow) dao.findFirst("from ProjectInfoFlow where id='" + fid + "'");
    }

    @Override
    public ProjectInfoFlow getCurrentFlow(String pid, String deptcode, String fid) throws Exception {
        return (ProjectInfoFlow) dao.findUnique("from ProjectInfoFlow where pid='" + pid + "' and deptcode='" + deptcode + "' and id='" + fid + "'");
    }

    @Override
    public ProjectInfoFlow getNextFlow(String pid, String deptcode, String fid) throws Exception {
        StringBuilder hql = new StringBuilder("from ProjectInfoFlow where pid='" + pid + "' and deptcode='" + deptcode + "' ");
        hql.append("and forder>(select forder from ProjectInfoFlow where id='" + fid + "') order by forder");
        return (ProjectInfoFlow) dao.findFirst(hql.toString());
    }

    @Override
    public Map<String, Object> getBSUsers(int page, int perpage, DUserResume user, Map<String, Object> param) throws Exception {
        StringBuffer queryHQL = new StringBuffer("select r.id,u.id as userid,u.ticketnum,r.code,r.name,r.cardno,r.educationname,r.tel,u.kcname,u.zhszpoint,u.zhszresult,u.gxcppoint,u.gxcpresult,u.zycppoint,u.zycpresult,u.point,u.result,u.notice,r.fid,u.seatnum,r.fqstate,r.fqfid,r.jname,u.op6,r.nrid,r.njname,u.remark bsremark, m.id mid,m.content mcontent,cardnototal.cardcount, hru.logintime, r.bsarrange, mc.ISCONFIRM bsconfirm, mc.CONFIRMTIME bsconfirmtime ");
        StringBuffer countHQL = new StringBuffer("select count(1) ");
        StringBuffer condition = new StringBuffer("from DUserResume r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,(select * from DoBS_User where fid='" + param.get("flowid").toString() + "') u,(select c.* from DOMS_CONFIRM c where c.TYPE='BS') mc,(select * from  Duserremark dm where  dm.fid like '%"+user.getPath()+"%'" + "   and dm.pid like '%"+user.getProid()+"%') m, hr_user hru where r.id=u.userid(+) and u.id= mc.MSUSERID(+) and r.id=m.rid(+) and r.userid=hru.id(+) and r.cardno = cardnototal.cardno(+) ");

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday<=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday>=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            condition.append(" and r.workexperience>='" + Integer.parseInt(workyearfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(workyearto)) {
            condition.append(" and r.workexperience<='" + Integer.parseInt(workyearto.toString()) + "'");
        }
        if (StringTools.notEmpty(heightfrom)) {
            condition.append(" and r.height>='" + Integer.parseInt(heightfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(heightto)) {
            condition.append(" and r.height<='" + Integer.parseInt(heightto.toString()) + "'");
        }

        Object result = param.get("bsresult");
        if (StringTools.trimNotEmpty(result)) {
            condition.append(" and u.result = '" + result + "' ");
        }
        int notice = Integer.parseInt(param.get("notice").toString());
        if (notice != -1) {
            condition.append(" and u.notice='" + notice + "' ");
        }

        Object bsconfirm = param.get("bsconfirm");
        if (StringTools.trimNotEmpty(bsconfirm)&&!bsconfirm.equals("-1")) {
            condition.append(" and mc.isconfirm='" + bsconfirm + "' ");
        }

        condition.append(BeanTools.hqlWhere(user, "r"));
        condition.append( " order by nvl(zhszpoint,0) desc");

        queryHQL.append(condition);
        countHQL.append(condition);

        //System.out.println(queryHQL);

        return DbUtil.pageSqlQueryMap(page, perpage, queryHQL.toString(),null, countHQL.toString(), dao);
    }

    @Override
    public Map<String, Object> getMSUsers(int page, int perpage, DUserResume user, Map<String, Object> param) throws Exception {
        StringBuffer queryHQL = new StringBuffer("select r.id,s.id as userid,r.code,r.name,r.cardno,r.educationname,r.workexperience,r.tel,s.starttime,s.address,s.notice,s.point,s.result,r.fid,r.fqstate,r.fqfid,r.jname,s.op7,r.nrid,r.njname,c.confirmtime,c.isconfirm,s.remark  msremark, m.id mid,m.content mcontent,cardnototal.cardcount, hru.logintime, r.msarrange ");

        StringBuffer countHQL = new StringBuffer("select count(1) ");
        StringBuffer condition = new StringBuffer();
        condition.append("from (select * from DoMS_User u where u.fid = '" + param.get("flowid").toString() + "') s,duserresume r ,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,(select * from  Duserremark dm where  dm.fid like '%"+user.getPath()+"%'" + "   and dm.pid like '%"+user.getProid()+"%') m, hr_user hru ,DoMS_Confirm c  where r.id=s.userid(+) and  r.id=m.rid(+) and r.userid=hru.id(+)  and s.id=c.msuserid(+) and r.cardno = cardnototal.cardno(+) ");

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday<=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday>=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            condition.append(" and r.workexperience>='" + Integer.parseInt(workyearfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(workyearto)) {
            condition.append(" and r.workexperience<='" + Integer.parseInt(workyearto.toString()) + "'");
        }
        if (StringTools.notEmpty(heightfrom)) {
            condition.append(" and r.height>='" + Integer.parseInt(heightfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(heightto)) {
            condition.append(" and r.height<='" + Integer.parseInt(heightto.toString()) + "'");
        }

        Object result = param.get("msresult");
        if (StringTools.trimNotEmpty(result)) {
            condition.append(" and s.result='" + result + "' ");
        }
        int notice = Integer.parseInt(param.get("notice").toString());
        if (notice != -1) {
            condition.append(" and s.notice='" + notice + "' ");
        }


        condition.append(BeanTools.hqlWhere(user, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);
        // System.out.println(queryHQL);

        return DbUtil.pageSqlQueryMap(page, perpage, queryHQL.toString(),null, countHQL.toString(), dao);
    }

    @Override
    public Map<String, Object> getSSUsers(int page, int perpage, DUserResume user, Map<String, Object> param) throws Exception {
        StringBuffer queryHQL = new StringBuffer("select r.id,s.id as userid,r.code,r.name,r.cardno,r.educationname,r.workexperience," +
                "r.tel,s.ssdate,s.bz,s.notice,s.point,s.result,s.op8,r.fid,r.fqstate,r.fqfid,r.jname,r.nrid,r.njname," +
                "m.id mid,m.content mcontent,cardnototal.cardcount, hru.logintime, r.msarrange ");

        StringBuffer countHQL = new StringBuffer("select count(1) ");
        StringBuffer condition = new StringBuffer();
        condition.append("from (select * from DoSS_User u where u.fid = '" + param.get("flowid").toString() + "') s,duserresume r ," +
                "(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal," +
                "(select * from  Duserremark dm where  dm.fid like '%"+user.getPath()+"%'" + "   and dm.pid like '%"+
                user.getProid()+"%') m, hr_user hru where r.id=s.userid(+) and  r.id=m.rid(+) and r.userid=hru.id(+)  and r.cardno = cardnototal.cardno(+) ");

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday<=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday>=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            condition.append(" and r.workexperience>='" + Integer.parseInt(workyearfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(workyearto)) {
            condition.append(" and r.workexperience<='" + Integer.parseInt(workyearto.toString()) + "'");
        }
        if (StringTools.notEmpty(heightfrom)) {
            condition.append(" and r.height>='" + Integer.parseInt(heightfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(heightto)) {
            condition.append(" and r.height<='" + Integer.parseInt(heightto.toString()) + "'");
        }

        Object result = param.get("msresult");
        if (StringTools.trimNotEmpty(result)) {
            condition.append(" and s.result='" + result + "' ");
        }
        int notice = Integer.parseInt(param.get("notice").toString());
        if (notice != -1) {
            condition.append(" and s.notice='" + notice + "' ");
        }

        condition.append(BeanTools.hqlWhere(user, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);

        return DbUtil.pageSqlQueryMap(page, perpage, queryHQL.toString(),null, countHQL.toString(), dao);
    }


    @Override
    public DUserResume getResume(String id) throws Exception {
        return (DUserResume) dao.findUnique("from DUserResume where id='" + id + "'");
    }

    @Override
    public DoOperationUser getSZUser(String fid, String uid) throws Exception {
        return (DoOperationUser) dao.findUnique("from DoOperationUser where fid='" + fid + "' and userid='" + uid + "'");
    }

    @Override
    public DoOperationUser getSZUser(String id) throws Exception {
        return (DoOperationUser) dao.findUnique("from DoOperationUser where id='" + id + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoOperationUser> getSZUsers(String fid, String[] uids) throws Exception {
        return dao.find("from DoOperationUser where fid='" + fid + "' and userid in(:idlist)", uids);
    }

    @Override
    public Map<String, Object> getSZUsers(int page, int perpage, DUserResume user, Map<String, Object> param) throws Exception {
        StringBuffer queryHQL = new StringBuffer("select r.id,s.id as userid,r.code,r.name,r.cardno,r.educationname,r.workexperience,r.tel,s.starttime,s.address,s.notice,s.point,s.result,s.bz szremark,r.fid,r.fqstate,r.fqfid,r.jname,s.op8,r.nrid,r.njname ,m.id mid,m.content mcontent,cardnototal.cardcount,hru.logintime ");

        StringBuffer countHQL = new StringBuffer("select count(1) ");
        StringBuffer condition = new StringBuffer();
        condition.append("from (select * from DoOperation_User u where u.fid = '" + param.get("flowid").toString() + "') s,duserresume r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,(select * from  Duserremark dm where  dm.fid like '%"+user.getPath()+"%'" + "   and dm.pid like '%"+user.getProid()+"%') m,HR_USER hru where 1=1 and r.id=m.rid(+) and r.userid=hru.id(+)  and r.id=s.userid(+) and r.cardno = cardnototal.cardno(+) ");

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday<=to_date('" + _date + "','yyyy-MM-dd')");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday>=to_date('" + _date + "','yyyy-MM-dd')");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            condition.append(" and r.workexperience>='" + Integer.parseInt(workyearfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(workyearto)) {
            condition.append(" and r.workexperience<='" + Integer.parseInt(workyearto.toString()) + "'");
        }
        if (StringTools.notEmpty(heightfrom)) {
            condition.append(" and r.height>='" + Integer.parseInt(heightfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(heightto)) {
            condition.append(" and r.height<='" + Integer.parseInt(heightto.toString()) + "'");
        }

        Object result = param.get("szresult");
        if (StringTools.trimNotEmpty(result)) {
            condition.append(" and s.result='" + result + "' ");
        }
        int notice = Integer.parseInt(param.get("notice").toString());
        if (notice != -1) {
            condition.append(" and s.notice='" + notice + "' ");
        }

        condition.append(BeanTools.hqlWhere(user, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);

        //System.out.println(queryHQL);

        return DbUtil.pageSqlQueryMap(page, perpage, queryHQL.toString(),null, countHQL.toString(), dao);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getSZPlan(String fid, String[] uids) throws Exception {
        StringBuilder sql = new StringBuilder();
        sql.append("select u.id,r.name,r.sexname,r.cardno,r.tel,r.jname,u.starttime,u.address,u.cont,u.point,u.pointuser,u.bz ");
        sql.append("from DUserResume r inner join DoOperation_User u on r.id=u.userid and u.fid='" + fid + "'  and r.id in(:idlist)");
        System.out.println(sql.toString());
        return dao.findSql(sql.toString(), uids);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getSZMsgUsers(String fid, String[] uids) throws Exception {
        StringBuilder sql = new StringBuilder();
        sql.append("select u.id,r.name,r.tel,u.starttime,u.address,u.notice ");
        sql.append("from DUserResume r inner join DoOperation_User u on r.id=u.userid and u.fid='" + fid + "'  and r.id in(:idlist)");
        System.out.println(sql.toString());
        return dao.findSql(sql.toString(), uids);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getSZResult(String[] id) throws Exception {
        String sql = "select r.jname,r.name,r.sexname,u.starttime,u.address,u.cont,u.point,u.pointuser,u.bz from DUserResume r inner join DoOperation_User u on r.id=u.userid and u.id in(:idlist)";
        return dao.findSql(sql, id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getBdUserCount(String pid) throws Exception {
        return dao.executeSQLQuery("select count(*),t.jid from DUSERRESUME t where t.proid='" + pid + "' and t.bdstate='已报到' group by t.jid");
    }


    @Override
    public Map<String, Object> getResumesMap(int page, int perpage, DUserResume resume, Map<String, Object> param) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer queryHQL = new StringBuffer("select r.*,m.id mid,m.content mcontent,cardnototal.cardcount cardnototal,hru.logintime  from VIEW_DUSERRESUME r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,( select * from  Duserremark dm where  dm.fid like '%"+resume.getPath()+"%'" + "   and dm.pid like '%"+resume.getProid()+"%' ) m,HR_USER hru where 1=1 and r.id=m.rid(+) and r.userid=hru.id(+) and r.cardno = cardnototal.cardno(+) ");
        StringBuffer countHQL = new StringBuffer("select count(1)  from VIEW_DUSERRESUME r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,( select * from  Duserremark dm where  dm.fid like '%"+resume.getPath()+"%'" + "   and dm.pid like '%"+resume.getProid()+"%' ) m,HR_USER hru where 1=1 and r.id=m.rid(+) and r.userid=hru.id(+) and r.cardno = cardnototal.cardno(+) ");
        StringBuffer condition = new StringBuffer();

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");
        Object rcount = param.get("rcount");


        Map<String, Object> _map = new HashMap<String, Object>();

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("agefrom", sdf.parse(_date));
            condition.append(" and r.birthday<=:agefrom");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("ageto", sdf.parse(_date));
            condition.append(" and r.birthday>=:ageto");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            _map.put("workyearfrom", Integer.parseInt(workyearfrom.toString()));
            condition.append(" and r.workexperience>=:workyearfrom");
        }
        if (StringTools.notEmpty(workyearto)) {
            _map.put("workyearto", Integer.parseInt(workyearto.toString()));
            condition.append(" and r.workexperience<=:workyearto");
        }
        if (StringTools.notEmpty(heightfrom)) {
            _map.put("heightfrom", Integer.parseInt(heightfrom.toString()));
            condition.append(" and r.height>=:heightfrom");
        }
        if (StringTools.notEmpty(heightto)) {
            _map.put("heightto", Integer.parseInt(heightto.toString()));
            condition.append(" and r.height<=:heightto");
        }


        if (StringTools.notEmpty(rcount)&&Integer.parseInt(rcount.toString())>0){
            _map.put("rcount", Integer.parseInt(rcount.toString()));
            condition.append(" and  nvl(r.rcount,0) >= :rcount ");
            resume.setRcount(null);
        }

        Object mcontent=param.get("mcontent");
        if(StringTools.trimNotEmpty(mcontent)){

            condition.append(" and m.content like '%"+mcontent.toString()+"%' ");
        }

        condition.append(BeanTools.hqlWhere(resume, "r"));
        queryHQL.append(condition);
        countHQL.append(condition);
        queryHQL.append(" order by r.adddate desc ");
        return DbUtil.pageSqlQueryMap(page,perpage,queryHQL.toString(),_map,countHQL.toString(),dao);
    }


    @Override
    public ProjectInfo getProject(String id) throws Exception {
        return (ProjectInfo) dao.findUnique("from ProjectInfo where id='" + id + "'");
    }
}
